<div class="sectionY">
	<a href="javascript:history.back()">
		<img src="__PUBLIC__/home/images/a4.png" class="a1" alt="">
	</a>
	<p class="p1">重置密码</p>
</div>
<div class="kong1"></div>
<div class="login_section2 login_section2x" >
	<form action="">
		<div class="f1 clearfix">
			<img src="__PUBLIC__/home/images/a5.png" class="im1" alt="">
			<input type="tel" name='phone'  id="phone" class="input1" placeholder="请输入手机号">
		</div>
		<div class="f1 clearfix" style="margin-bottom: 0px">
			<img src="__PUBLIC__/home/images/a3.png" alt="">
			<input type="text" name='codes' class="input1" placeholder="请输入验证码">
			<span class="sr_btn" id="getVcode">获取验证码</span>
		</div>
		<div class="f1 clearfix" style="margin-bottom: 0px">
			<img src="__PUBLIC__/home/images/a3.png" alt="">
			<input type="password" name='pwd' class="input1" placeholder="请输入新的密码">
		</div>
		<div class="f1 clearfix" style="margin-bottom: 0px">
			<img src="__PUBLIC__/home/images/a3.png" alt="">
			<input type="password" name='newpwd' class="input1" placeholder="请再次输入新的密码">
		</div>
		<div class="sub">
			<button class="but1" id="sbt" type="button">提交修改</button>
		</div>
	</form>
</div>
<script>
    var is_enable=true;
    $(function(){
        /*获取验证码*/
        $(".s3").click(function(){
            var times = 60;
            var phone	= $('#phone').val();
            if(phone==''){
                layer.alert('请输入手机号!',{icon: 2,shade:0.8,title:"错误提示:"});return false;
            }
            /*手机号格式正确，发送验证码并倒计时开始*/
            $.ajax({
                type: 'POST',
                url: "{:url('Paytype/sendsms')}",
                dataType: "html",
                data: "tel=1&phone="+phone,
                success:function(msg){
                    msg= JSON.parse(msg);
                    if(msg.result_code==0){
                        layer.alert(msg.result_info,{icon: 1,shade:0.8,title:"成功提示:"});
                        is_enable = false;
                        $("#getVcode").html(times+"秒后发送");
                        var index = setInterval(function () {
                            if(times == 0){
                                clearInterval(index);
                                is_enable = true;
                                $("#getVcode").html("发送验证码");
                            }else{
                                times--;
                                $("#getVcode").html(times+"秒后发送");
                            }
                        }, 1000);
                    }else {
                        layer.alert(msg.result_info,{icon: 2,shade:0.8,title:"错误提示:"});
                    }
                },
                error:function(){
                    layer.alert('系统繁忙，请稍后再试！',{icon: 2,shade:0.8,title:"错误提示:"});
                }
            });
        });

        /*重置密码*/
        $("#sbt").click(function(){
            var codes	= $('input[name=codes]').val();
            var pwds	= $('input[name=pwd]').val();
            var newpwd	= $('input[name=newpwd]').val();
            var phone	= $('#phone').val();

            if(pwds==''){
                layer.alert('请输入新密码!',{icon: 2,shade:0.8,title:"错误提示:"});return false;
            }
            if(pwds!=newpwd){
                layer.alert('两次输入的密码不一致！',{icon: 2,shade:0.8,title:"错误提示:"});return false;
            }
            if(phone==''){
                layer.alert('请输入手机号!',{icon: 2,shade:0.8,title:"错误提示:"});return false;
            }
            if(codes==''){
                layer.alert('请输入验证码！',{icon: 2,shade:0.8,title:"错误提示:"});return false;
            }
            $.ajax({
                type: 'POST',
                url: "{:url('Index/doforget')}",
                dataType: "html",
                data: "tel=1001&codes="+codes+"&pwds="+pwds+"&phone="+phone,
                success:function(msg){
                    msg= JSON.parse(msg);
                    if(msg.result_code==0){
                        layer.msg('修改成功！',{icon: 1,shade:0.8,time: 2000,end:function(){
                                window.location.href="{:url('Index/index')}";
                            }});
                        return false;
                    }else{
                        layer.alert(msg.result_info,{icon: 2,shade:0.8,title:"错误提示:"});
                    }
                },
                error:function(){
                    layer.alert('系统繁忙，请稍后再试！',{icon: 2,shade:0.8,title:"错误提示:"});
                }
            });
        });
    })
</script>
